<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.cn.Mapper.userMapper.UserMapper" %>
<%@ page import="com.cn.util.SqlsesstionUtil" %>
<%@ page import="com.cn.entity.user.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cn.Mapper.enployeeMapper.EmployeeMapper" %>
<%@ page import="com.cn.entity.enployee.Employee" %><%--
  Created by IntelliJ IDEA.
  User: yujiajing
  Date: 2022/10/3
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>人员管理列表</title>
    <%--  引入jQuery包  --%>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>

    <!-- 引入layui css -->
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />

    <!-- 引入layui js -->
    <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>

</head>

<body>

<script>
    function ConfirmDelete(id){
        if(confirm("确认删除数据？")){
            OperatorUser(id);

        }
    }

    function OperatorUser(id) {

        $.ajax({

            type : "post",

            url : "employee/delete",

            dateType : "String",

            data : {

                id : id

            },

            success : function(data) {
                alert("删除成功");
                $("#tr_"+id).remove();


            },

            error : function() {
            alert("失败");

                $("#tr_"+id).remove();

            }

        });

    }
</script>

<%
    SqlSession sqlSession = SqlsesstionUtil.getSqlSession();
    EmployeeMapper employeeMapper=sqlSession.getMapper(EmployeeMapper.class);
    List<Employee> employeeList= employeeMapper.showEmployee();
%>
<table id="UserTable" class="layui-table"  >

    <tr>
        <td>工号</td>
        <td>姓名</td>
        <td>所在店名</td>
        <td >所在部门</td>
        <td>操作</td>
    </tr>

    <%for (Employee employee:employeeList){%>
    <%--  --%>
    <tr id="tr_<%=employee.getEmployee_id()%>">
        <%--    --%>
        <td><%=employee.employee_id%></td>
        <td><%=employee.getEmployee_name()%></td>
        <td><%=employee.getshop_name()%></td><td><%=employee.getdepartment_name()%></td>


        <td>
<%--            <a class="layui-btn layui-btn-xs" lay-event="edit" href="UpdateUser.jsp?id=<%=user.getId()%>&username=<%=user.getUsername()%>&password=<%=user.getPassword()%>">编辑</a>--%>
            <a class="layui-btn layui-btn-danger layui-btn-xs"  href="javascript:void(0);"id="del_<%=employee.getEmployee_id()%>"  onclick="ConfirmDelete(<%=employee.getEmployee_id()%>)">解雇</a>

        </td>
        <%}%>
    </tr >
</table>
<a href="InsertUser.jsp?">雇佣新员工</a>
</body>
</html>

